Imports RIBS.BusinessLogicLayer
Imports RIBS.BusinessLogicLayer.Reports
Imports RIBS.Code.GlobalModule1

Public Class frmSummary


    Public Function BindReport(ByVal ds As DataSet) As Boolean
        Try
            Cursor = Cursors.WaitCursor
            CrystalReportViewer1.Enabled = True
            CrystalReportViewer1.Visible = True
            Application.DoEvents()
            Dim oRpt As ReportDocument

            oRpt = CrystalReportViewer1.ReportSource
            oRpt.SetDataSource(ds)

            CrystalReportViewer1.ReportSource = oRpt
            CrystalReportViewer1.Zoom(80)
            Cursor = Cursors.Default
        Catch ex As Exception
            DisplayErrors(ex)
        End Try
    End Function

    Private Sub btnRefresh_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRefresh.Click
        Try
            Dim ds As New DataSet
            Dim UserList As String = ""
            Dim Actions As String = ""
            Cursor = Cursors.WaitCursor
            Application.DoEvents()
            '*********************************************************
            'Options
            ds.Tables.Add(New dsDBSchema.OptionsDataTable)

            Dim dr As DataRow
            dr = ds.Tables("Options").NewRow
            dr("FromDate") = dtDate.Text
            dr("ReportTitle") = txtReportTitle.Text
            dr("PageTitle") = txtPageTitle.Text
            ds.Tables("Options").Rows.Add(dr)
            
            My.Settings.ReportsSummaryReportTitle = txtReportTitle.Text
            My.Settings.ReportsSummaryPageTitle = txtPageTitle.Text
            My.Settings.ReportsSummaryDate = dtDate.Value
            My.Settings.Save()


            BindReport(SummaryReport.SummaryReport(ds))
            Cursor = Cursors.Default
        Catch ex As Exception
            DisplayErrors(ex)
        End Try


    End Sub

    Private Sub frmSummary_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            Cursor = Cursors.WaitCursor
            'Dim dt As DataTable
            
            txtReportTitle.Text = My.Settings.ReportsSummaryReportTitle
            txtPageTitle.Text = My.Settings.ReportsSummaryPageTitle
            If My.Settings.ReportsSummaryDate = Nothing Then
                dtDate.Value = Now()
            Else
                dtDate.Value = My.Settings.ReportsSummaryDate
            End If


            CrystalReportViewer1.Enabled = False
            CrystalReportViewer1.Visible = False


        Catch ex As Exception
            DisplayErrors(ex)
        Finally
            Cursor = Cursors.Default
        End Try
    End Sub

    Private Sub dtDate_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dtDate.ValueChanged

    End Sub
End Class